﻿// ParseLib - An open source library for natural language processing.
// Copyright (C) Kais Dukes, 2012. E-mail: kais@kaisdukes.com
// http://parselib.org

using System.Collections.Generic;

namespace ParseLib.Algorithms
{
    public class Partition
    {
        public int DataCount { get; private set; }
        public int StartIndex { get; private set; }
        public int EndIndex { get; private set; }

        public Partition(int partitionNumber, int partitionCount, int dataCount)
        {
            // Partition.
            DataCount = dataCount;
            var partitionSize = DataCount / partitionCount;

            // Inside interval.
            StartIndex = (partitionNumber - 1) * partitionSize;
            EndIndex = (partitionNumber == partitionCount ? DataCount : StartIndex + partitionSize) - 1;
        }

        public IEnumerable<int> Inside
        {
            get
            {
                for (var i = StartIndex; i <= EndIndex; i++)
                {
                    yield return i;
                }
            }
        }

        public IEnumerable<int> Outside
        {
            get
            {
                for (var i = 0; i < StartIndex; i++)
                {
                    yield return i;
                }
                for (var i = EndIndex; i < DataCount; i++)
                {
                    yield return i;
                }
            }
        }
    }
}
